﻿using Socium.Domain.Persons;
using Socium.Presentation;

namespace Socium.Persons {
	class GroupViewModel : FormViewModel<Group> {
		#region Constructors

		public GroupViewModel(Group group) : base(group) {
			InitializeProperties(group);
		}

		public GroupViewModel() {}

		#endregion

		#region Editable properties

		string _name;

		public string Name {
			get { return _name; }
			set {
				_name = value;
				OnPropertyChanged("Name");
			}
		}

		string _description;

		public string Description {
			get { return _description; }
			set {
				_description = value;
				OnPropertyChanged("Description");
			}
		}

		void InitializeProperties(Group group) {
			Name = group.Name;
			Description = group.Description;
		}

		#endregion

		protected override void Update(Group model) {
			InitializeProperties(model);
		}

		#region Save

		protected override Group CreateModel() {
			return new Group();
		}

		public override bool CanSave() {
			if (string.IsNullOrEmpty(_name)) {
				return false;
			}

			return true;
		}

		protected override void Save(Group model) {
			model.Name = _name;
			model.Description = _description;
		}

		#endregion

		protected override string GetDisplayName(Group model) {
			return model.Name;
		}

		protected override string GetDefaultDisplayName() {
			return "New group";
		}
	}
}
